/**
 * student
 */
package com.thinkgem.jeesite.zmis.student.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.zmis.student.entity.ZmisStudent;
import com.thinkgem.jeesite.zmis.student.service.ZmisStudentService;

/**
 * 学生Controller
 * @author ll
 * @version 2017-10-11
 */
@Controller
@RequestMapping(value = "${adminPath}/student/zmisStudent")
public class ZmisStudentController extends BaseController {

	@Autowired
	private ZmisStudentService zmisStudentService;
	
	@ModelAttribute
	public ZmisStudent get(@RequestParam(required=false) String id) {
		ZmisStudent entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = zmisStudentService.get(id);
		}
		if (entity == null){
			entity = new ZmisStudent();
		}
		return entity;
	}
	
	@RequiresPermissions("student:zmisStudent:view")
	@RequestMapping(value = {"list", ""})
	public String list(ZmisStudent zmisStudent, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ZmisStudent> page = zmisStudentService.findPage(new Page<ZmisStudent>(request, response), zmisStudent); 
		model.addAttribute("page", page);
		return "zmis/student/zmisStudentList";
	}

	@RequiresPermissions("student:zmisStudent:view")
	@RequestMapping(value = "form")
	public String form(ZmisStudent zmisStudent, Model model) {
		model.addAttribute("zmisStudent", zmisStudent);
		return "zmis/student/zmisStudentForm";
	}

	@RequiresPermissions("student:zmisStudent:edit")
	@RequestMapping(value = "save")
	public String save(ZmisStudent zmisStudent, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, zmisStudent)){
			return form(zmisStudent, model);
		}
		zmisStudentService.save(zmisStudent);
		addMessage(redirectAttributes, "保存学生成功");
		return "redirect:"+Global.getAdminPath()+"/student/zmisStudent/?repage";
	}
	
	@RequiresPermissions("student:zmisStudent:edit")
	@RequestMapping(value = "delete")
	public String delete(ZmisStudent zmisStudent, RedirectAttributes redirectAttributes) {
		zmisStudentService.delete(zmisStudent);
		addMessage(redirectAttributes, "删除学生成功");
		return "redirect:"+Global.getAdminPath()+"/student/zmisStudent/?repage";
	}

}